// https://www.luogu.com.cn/problem/P2871

#include <iostream>
#include <algorithm>
using namespace std;

int max_weights;
int weights[4321], values[4321];
int dp[13450];

int main() {
    int n;
    scanf("%d%d",&n, &max_weights);
    for (int i = 1; i <= n; i++) {
        scanf("%d%d", &weights[i], &values[i]);
    }

    dp[0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = max_weights; j >= weights[i]; j--) {
            dp[j] = max(dp[j], dp[j-weights[i]] + values[i]);
        }
    }

    printf("%d\n", dp[max_weights]);
    return 0;
}